package com.hr.mapper;

import com.hr.domain.dto.UserDTO;
import com.hr.domain.po.User;
import com.hr.domain.query.UserQueryParams;
import com.hr.domain.vo.ClientUserInfoVO;
import com.hr.domain.vo.LoginUserVO;
import com.hr.domain.vo.UserVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author 86150
* @description 针对表【user(用户表)】的数据库操作Mapper
* @createDate 2025-09-22 15:58:46
* @Entity com.hr.domain.po.User
*/
@Mapper
public interface UserMapper {
    /**
     * 获取所有用户
     * @return int List<UserVO>
     */
    List<UserVO> getAllUsers();

    /**
     * 分页获取用户分页列表
     * @return List<UserVO>
     */
    List<UserVO> getUserPageList(UserQueryParams queryParams);

    /**
     * 禁用、启用账户
     * @return int
     */
    @Update("update user set status = #{status} where id = #{id}")
    int updateUserStatus(@Param("id") Long id, @Param("status") Integer status);

    /**
     * 新增用户
     * @return row
     */
    @Update("insert into user(username,password,role_id,phone,email,real_name,id_card) " +
            "values(#{username},#{password},#{roleId},#{phone},#{email},#{realName},#{idCard})")
    int addUser(User user);
    /**
     * 根据用户名查询用户
     * @return User
     */
    @Select("select username from user where username = #{username}")
    User findByUsername(String username);

    /**
     * 根据id查询用户
     * @return User
     */
    @Select("select * from user where id = #{id}")
    User SelectById(Long id);

    /**
     * 根据用户名和密码查询用户
     * @return User
     */
    @Select("select id, rname, roleId ,username,realName ,status from (select u.id , r.name rname,r.id AS roleId,username, password, phone,status,email, real_name as realName, id_card, create_time, update_time\n" +
            "    from user u left join role r on u.role_id = r.id) as ur where ur.username = #{username} and ur.password = #{password}")
    LoginUserVO SelectByIdAndusername(@Param("username") String username,@Param("password") String password);
    /**
     * 根据id查询用户（查询回显）
     * @return User
     */
    UserVO OtherSelectById(Long id);

    /**
     * 修改用户信息
     * @return int
     */
    int update(User user);

    /**
     * 根据id查询用户信息（查询用户信息）
     * @return User
     */
    ClientUserInfoVO selectById(Long id);

    /**
     * 根据id批量查询用户信息
     * @return List<User>
     */

    List<User> selectBatchIds(@Param("ids") List<Long> userIds);
}




